package com.xtm.exercise.mq;

import com.alibaba.fastjson.JSONObject;
import com.xtm.exercise.mq.base.IMQService;
import com.xtm.exercise.mq.base.ProductInfo;
import com.xtm.exercise.mq.base.TopicConst;
import com.xtm.mq.common.model.TopicInfo;
import com.xtm.mq.common.service.MqTemplate;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
@RequiredArgsConstructor
public class MQService implements IMQService {

    private final MqTemplate rocketTemplateImpl;

    @Override
    public void stringTest () {
        TopicInfo<String> stringInfo = new TopicInfo<>();
        stringInfo.setTopic(TopicConst.XTM_SERVICE_STRING_TOPIC);
        stringInfo.setMsg("这是一条消息数据");
        rocketTemplateImpl.syncSend(stringInfo);
    }

    @Override
    public void integerTest () {
        TopicInfo<Integer> integerInfo = new TopicInfo<>();
        integerInfo.setTopic(TopicConst.XTM_SERVICE_INTEGER_TOPIC);
        integerInfo.setMsg(20250315);
        rocketTemplateImpl.syncSend(integerInfo);
    }

    @Override
    public void objectTest () {
        TopicInfo<ProductInfo> productInfo = new TopicInfo<>();
        productInfo.setTopic(TopicConst.XTM_SERVICE_PRODUCT_TOPIC);
        productInfo.setMsg(new ProductInfo("苹果", BigDecimal.valueOf(200)));
        rocketTemplateImpl.syncSend(productInfo);
    }

}
